<?php
/**
 * Created by litong on Date: 2019/2/25 0025 上午 7:54
 */
$host="localhost";$username="root";$password="";$dbname="php_study";
$connection = new mysqli($host, $username, $password, $dbname);
if($connection->connect_error){
  echo $connection->connect_error;
}
$sql="SELECT id, firstname, lastname FROM my_guests";
$result=$connection->query($sql);//查询数据
if($result->num_rows>0){
  while($row=$result->fetch_assoc()){ //取出一行数据
    echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"].PHP_EOL;
  }
}